<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>视频上传</title>
		<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<meta name="format-detection" content="telephone=no">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	</head>
	<style>
		.row {
		  -webkit-appearance: none;
		     -moz-appearance: none;
		          appearance: none;
		  background-color: #fff;
		  border-color: #cccccc;
		  border-radius: 3px;
		  border-style: solid;
		  border-width: 1px;
		  box-shadow: none;
		  box-sizing: border-box;
		  color: #222f3e;
		  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
		  font-size: 16px;
		  line-height: 24px;
		  margin: 0;
		  min-height: 34px;
		  outline: none;
		  padding: 5px 4.75px;
		  resize: none;
		  width: 100%;
		}
		.conent{
			width: 100%;
		}
		#video-url{
			-webkit-appearance: none;
			     -moz-appearance: none;
			          appearance: none;
			  background-color: #fff;
			  border-color: #cccccc;
			  border-radius: 3px;
			  border-style: solid;
			  border-width: 1px;
			  box-shadow: none;
			  box-sizing: border-box;
			  color: #222f3e;
			  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
			  font-size: 16px;
			  line-height: 24px;
			  margin: 0;
			  min-height: 34px;
			  outline: none;
			  padding: 5px 4.75px;
			  resize: none;
			  width: 80%;
		}
		.addfile{
			-webkit-appearance: none;
			     -moz-appearance: none;
			          appearance: none;
			  background-color: #fff;
			  border-width: 0;
			  box-shadow: none;
			  box-sizing: border-box;
			  color: #222f3e;
			  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
			  font-size: 16px;
			  line-height: 24px;
			  margin: 0;
			  min-height: 34px;
			  outline: none;
			  padding: 5px 4.75px;
			  resize: none;
			  width: 10%;
		}
		.addfile span{
			width: 100%;
			height: 100%;
		}
	</style>
	<body>
		<div class="row">
			<div class="conent">
				<input type="text" value="" id="video-url" />
				<button class="addfile">
					<span >
						<svg width="25" height="25">
							<path d="M19 4a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2h-4v-2h4V8H5v10h4v2H5a2 2 0 0 1-2-2V6c0-1.1.9-2 2-2h14zm-8 9.4l-2.3 2.3a1 1 0 1 1-1.4-1.4l4-4a1 1 0 0 1 1.4 0l4 4a1 1 0 0 1-1.4 1.4L13 13.4V20a1 1 0 0 1-2 0v-6.6z"
							 fill-rule="nonzero"></path>
						</svg>
					</span>	
				</button>

			</div>
		</div>
	</body>
	<script>
		var editor = parent.tinymce.activeEditor;
		var videof = editor.videof;
		console.log(editor)
		console.log(editor.baseURI.source)
		videof.res = []; //存放本地文件的数组
		var blobInfo = {
			file: null
		}
		blobInfo.blob = function() {
			return this.file;
		}
		var upload_handler = videof.images_upload_handler;
		var upload_base_path = videof.images_upload_base_path;

		document.querySelector('.row .addfile').addEventListener('click', () => {
			var input = document.createElement('input');
			input.setAttribute('type', 'file');
			//input.setAttribute('multiple', 'multiple');
			input.setAttribute('accept', videof.videof_filetype);
			input.click();
			input.onchange = function() {
				var files = this.files;
				var fileName = files[0].name;
				var s =  fileName.substring(fileName.lastIndexOf(".")+1)
				console.log(s)
				var type = videof.videof_filetype;
				console.log(type)
				if(type.indexOf(s) > -1){
					upAllFiles(files[0])
				}else{
					alert('请上传视频');
				}
			}
		});

		function upAllFiles(n) {
			blobInfo.file = n;
			upload_handler(blobInfo, function(url) {
				console.log(url)
				var input = document.getElementById("video-url");
				console.log(input)
				input.value = url;
			}, function(err) {
				alert(err);
			});
		}
	</script>
</html>
